import com.cn.Student;
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;

public class Demo1 {

    public static void main(String[] args) {
        ArrayList<Student> arrayList=new ArrayList<Student>();
        StorageName(arrayList);
        printStudent(arrayList);
        randomStudent(arrayList);
    }
    //储存全班学生姓名
    public static void StorageName(ArrayList<Student> arrayList){
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入学生人数:");
        int a= scanner.nextInt();
        for ( int i=0;i<a;i++){
            Student student=new Student();
            System.out.println("第"+(i+1)+"学生姓名：" );
            student.name=scanner.next();
            System.out.println("第"+(i+1)+"学生年龄：");
            student.age=scanner.nextInt();
            arrayList.add(student);
        }

    }
    //打印全班学生的信息
    public static void printStudent(ArrayList<Student> arrayList){
        for (int i=0;i<arrayList.size();i++){
            Student student=arrayList.get(i);
            System.out.println("第"+(i+1)+"名学生姓名："+student.name+"年龄"+student.age);
        }
    }
    //随机选取一名幸运儿
    public static void  randomStudent(ArrayList<Student> arrayList){
        Random random=new Random();
        int index=random.nextInt(arrayList.size());
        Student student=arrayList.get(index);
        System.out.println("幸运儿"+student.name+"今年"+student.age);

    }

}
